<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <meta http-equiv="X-UA-Compatible" content="ie=edge"/>
    <title>Document</title>
</head>
<body>
    <div>
        <input type="text" id="ipt"/>
        <h3 id="username"></h3>
    </div>
    <script>
        let user = {};
        let value = '';

        let ipt = document.querySelector('#ipt');
        let username = document.querySelector('#username');

        Object.defineProperty(user,'username',{
            set(newValue){
                console.log("设置值")
                value = newValue;
                ipt.value = newValue;
                username.innerHTML = newValue;
            },
            get(){
                console.log("获取值")
                return value 
            }
        })

        //1.添加input的事件
        ipt.addEventListener('input',(e) => {
            user.username = e.target.value;
        })

    </script>
</body>
</html>